package com.ybbase.framework.config.activiti.custom.util;
import java.util.ArrayList;
import java.util.List;

import com.ybbase.framework.model.po.system.User;
import org.activiti.engine.identity.Group;
import org.activiti.engine.impl.persistence.entity.GroupEntity;
import org.activiti.engine.impl.persistence.entity.UserEntity;

/**
 * @author cg
 * @date 2019-08-22 15:04
 * @DEC
 */
public class ActivitiUserUtil {
    public static UserEntity toActivitiUser(User bUser){
        UserEntity userEntity = new UserEntity();
        userEntity.setId(bUser.getId().toString());
        userEntity.setFirstName(bUser.getName());
        userEntity.setLastName("");
        userEntity.setPassword(bUser.getPassword());
        userEntity.setEmail(bUser.getEmail());
        userEntity.setRevision(1);
        return userEntity;
    }

    public static GroupEntity toActivitiGroup(String code){
        GroupEntity groupEntity = new GroupEntity();
        groupEntity.setRevision(1);
        groupEntity.setType("assignment");
        groupEntity.setId(code);
        return groupEntity;
    }

    public static List<Group> toActivitiGroups(List<String> roleCodeList){
        List<Group> groups = new ArrayList<>();
        for (String code : roleCodeList) {
            GroupEntity groupEntity = toActivitiGroup(code);
            groups.add(groupEntity);
        }
        return groups;
    }
}
